package com.atguigu.system.service;

import com.atguigu.model.system.SysLoginLog;
import com.atguigu.model.system.SysRole;
import com.atguigu.model.vo.loginlog.SysLoginLogQueryReqVo;
import com.atguigu.model.vo.loginlog.SysLoginLogQueryRespVo;
import com.atguigu.system.manager.SysLoginLogManager;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * LoginLogServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2023/10/26
 */
@Service
public class SysLoginLogServiceImpl implements SysLoginLogService {

    @Autowired
    private SysLoginLogManager sysLoginLogManager;

    @Override
    public void recordLoginLog(String username, Integer status, String ipaddr, String message) {
        SysLoginLog sysLoginLog = new SysLoginLog();
        sysLoginLog.setUsername(username);
        sysLoginLog.setIpaddr(ipaddr);
        sysLoginLog.setStatus(status);
        sysLoginLog.setMsg(message);
        sysLoginLog.setAccessTime(new Date());
        sysLoginLogManager.save(sysLoginLog);
    }

    /**
     * 获取分页列表
     * @param pageParam
     * @param reqVo
     * @return
     */
    public IPage<SysLoginLogQueryRespVo> getPageList(Page<SysLoginLog> pageParam, SysLoginLogQueryReqVo reqVo) {
        return sysLoginLogManager.getPageList(pageParam,reqVo);
    }
}
